#pragma once
#include"BRTree.h"

namespace bit
{
    template<class K,class V>
    class map
    {
    public:
        struct MapKeyOfT
        {
            const K& operator()(const pair<K,V>& kv)
            {
                return kv.first;
            }
        };

        typedef typename BRTree<K, pair<const K,V>, MapKeyOfT>::iterator iterator;
        typedef typename BRTree<K, pair<const K,V>, MapKeyOfT>::const_iterator const_iterator;

        iterator begin()
        {
            return _t.begin();
        }

        iterator end()
        {
            return _t.end();
        }

        const_iterator begin() const
        {
            return _t.begin();
        }

        const_iterator end() const
        {
            return _t.end();
        }

        pair<iterator, bool> insert(const pair<K,V>& data)
        {
            return  _t.Insert(data);
        }

        V& operator[](const K& data)
        {
            pair<iterator, bool> ret = insert(make_pair(data, V()));
            return ret.first->second;
        }

    private:
        BRTree<K, pair<const K,V>, MapKeyOfT> _t;
    };
}
